#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:et:sw=4:sts=4:ai:nosi
# Copyright (c) 2012 Flibusta Quotes Team
#
# This file is part of Flibusta Quotes.
#
# Flibusta Quotes is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import webapp2
from handlers import (
    AddQuoteHandler,
    AuthorHandler,
    BasicTemplateHandler,
    CommentsHandler,
    DiscussHandler,
    EditQuoteHandler,
    QuotesHandler,
    SearchHandler,
    SignHandler,
    SingleQuoteHandler,
    StatsHandler
)
from filters import (
    nl2br
)
from webapp2_extras import jinja2

# Register template filter
jinja2.default_config['filters'] = {
    'nl2br': nl2br
}

# Deprecated
def quote_redirect(request, _id):
    return webapp2.redirect('/' + _id)

app = webapp2.WSGIApplication([
    ('/', QuotesHandler),
    ('/about', BasicTemplateHandler('about.html')),
    ('/add', AddQuoteHandler),
    ('/comments', CommentsHandler),
    ('/preferences', BasicTemplateHandler('pref.html')),
    ('/search', SearchHandler),
    ('/sign', SignHandler),
    ('/stat', StatsHandler),
    webapp2.Route('/author/<author:[^/]+>', AuthorHandler),
    webapp2.Route(r'/<qid:\d+>/discuss', DiscussHandler),
    webapp2.Route(r'/<qid:\d+>/edit', EditQuoteHandler),
    webapp2.Route(r'/<qid:\d+>', SingleQuoteHandler),
    (r'/quote/(\d+)', quote_redirect),
], debug=True)

